package com.vaadin.tutorial.crm.backend.service;

import com.vaadin.tutorial.crm.backend.entity.Score;
import com.vaadin.tutorial.crm.backend.repository.ScoreRepository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.vaadin.tutorial.crm.backend.util.CommonVar.SAVE_NULL;

/**
 * @Description:
 * @Author: Fan
 * @Date: 2021/1/16 20:40
 * @Version 1.0
 */
@Service
public class ScoreService {
    private static final Logger LOGGER = Logger.getLogger(ScoreService.class.getName());
    private final ScoreRepository scoreRepository;

    public ScoreService(ScoreRepository scoreRepository) {
        this.scoreRepository = scoreRepository;
    }

    public List<Score> findAll(){
        return scoreRepository.findAll();
    }

    public List<Score> findAll(String stringFilter){
        if(stringFilter == null || stringFilter.isEmpty()){
            return scoreRepository.findAll();
        }else{
            return scoreRepository.search(stringFilter);
        }
    }

    public long count() {
        return scoreRepository.count();
    }

    public void delete(Score course) {
        scoreRepository.delete(course);
    }

    public void save(Score course) {
        if (course == null) {
            LOGGER.log(Level.SEVERE,
                    SAVE_NULL);
            return;
        }
        scoreRepository.save(course);
    }

}
